package org.jfsm.demo.ccounter;

import java.io.PrintStream;

import org.jfsm.concurrent.ContextExecutor;
import org.jfsm.demo.ccounter.cnt.CntFSM;
import org.jfsm.demo.ccounter.cnt.CntRequest;
import org.jfsm.demo.ccounter.echo.EchoFSM;
import org.jfsm.demo.ccounter.timer.TimerFSM;
import org.jfsm.log.StreamLogger;

public class CntController {

    String logId;
    int numThreads = 1;

    public static final int numServers = 8;

    public static final long sampleTime = 1000;
    public static final long holdTime = 2000;

    public void start() throws Exception {
        if (logId != null) {
            new StreamLogger(new PrintStream("fsm" + logId + ".log"), true).setAsDefault();
        }

        ContextExecutor executor = new ContextExecutor(numThreads, 16000);

        CntFSM fsm = new CntFSM();
        fsm.timer = fsm.getReference(new TimerFSM().createInstance());
        fsm.echo = fsm.getReference(new EchoFSM().createInstance(executor));

        CntRequest dispatcher = fsm.createInstance(executor).getInput();
        dispatcher.start.dispatch(dispatcher.newContext());
    }

    public static void main(String args[]) {
        try {
            new CntController().start();

        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

}
